package com.yunfangdata.web.controller;

import com.yunfangdata.domain.Colleges;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.ICollegesService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("colleges")
public class CollegesController {
    @Autowired
    private ICollegesService collegesService;


    @RequestMapping("")
    public String index(){
        return "colleges/list";
    }
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        return collegesService.query(qo);
    }

  @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Colleges entity) {
        JsonResult result = new JsonResult();
        try{
            collegesService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return  result;
    }

    //删除操作
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult result = new JsonResult();
        try{
            collegesService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("删除失败");
        }
        return  result;
    }






    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Colleges entity) {
        JsonResult result = new JsonResult();
        try{
            collegesService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return  result;
    }
}